<template>
  <div class="wrapper">
    <v-head @config="setPrintConfig"></v-head>
    <v-sidebar></v-sidebar>
    <div class="content-box" :class="{'content-collapse':collapse}">
      <!-- <v-tags></v-tags> -->
      <div class="content">
        <transition name="move" mode="out-in">
          <keep-alive :include="tagsList">
            <router-view v-if="isRouterAlive">

            </router-view>
          </keep-alive>
        </transition>
        <bottom></bottom>
      </div>
    </div>
    <!-- 打印设置 -->
    <lodop-config ref="config" />
  </div>
</template>

<script>
import vHead from '../components/Header';
import vSidebar from '../components/SlideBar';
import vTags from '../components/Tags';
import bus from '../common/bus';
import bottom from '../components/bottom';
import lodopConfig from '../components/common/lodop/config'

export default {
  provide() {
    return {
      reload: this.reload,
    }
  },
  data() {
    return {
      tagsList: [],
      collapse: false,
      isRouterAlive: true,
    }
  },
  components: {
    vHead, vSidebar, vTags, bottom, lodopConfig
  },
  methods: {
    reload() {
      this.isRouterAlive = false;
      this.$nextTick(function () {
        this.isRouterAlive = true
      })
    },
    // 打印配置
    setPrintConfig() {
      this.$refs.config.open()
    }
  },
  created() {
    bus.$on('collapse', msg => {
      this.collapse = msg;
    })
    // 只有在标签页列表里的页面才使用keep-alive，即关闭标签之后就不保存到内存中了。
    bus.$on('tags', msg => {
      let arr = [];
      for (let i = 0, len = msg.length; i < len; i++) {
        msg[i].name && arr.push(msg[i].name);
      }
      this.tagsList = arr;
    })
  }
}
</script>
